<title>应用市场</title>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>应用管理</cite></a>
    <a><cite>应用市场</cite></a>
  </div>
</div>

<div class="layui-fluid">
	<iframe id="if" src="https://store.wendasns.com/market/index.html" frameborder="0" style="width: 100%;height: 800px;"></iframe>
</div>
<script>
var action = {
	index: 1,
	ready: function(data){
		this.index = layui.admin.popup({
			title: '安装-'+data.name
			,area: ['220px','auto']
			,shadeClose: false
			,type: 2
			,content: [data.href+'?token={$token}&redirect={:urlencode($redirect)}&addonids='+data.alias,'no']
		});
	},
	install: function(data){
	    layui.$.ajax({
	      url: '{:url('/plugin/install')}'
	      ,type: 'GET'
	      ,data: {addonids:data.addonids}
	      ,dataType: 'json'
	      ,success: function(res){
	        if(res.code===0){
	          action.inspect(data.addonids);
	        }else{
	          document.getElementById('layui-layer-iframe'+action.index).contentWindow.postMessage(res.msg, '*');
	        }
	      }
	    });
	},
	inspect: function(addonids){
	    layui.$.ajax({
	      url: '{:url('/plugin/check')}'
	      ,type: 'GET'
	      ,data: {addonids:addonids,step:2}
	      ,dataType: 'json'
	      ,success: function(res){
	        if(res.code===0){
	          layer.msg('安装完毕',{
				  icon: 6,
				  time: 2000
				}, function(){
				  layer.closeAll('iframe');
				});
	        }else if(res.code===200){
	          setTimeout('action.inspect("'+addonids+'")',2000);
	        }else{
	          layer.msg(res.msg,{icon: 2},function(){
	          	layer.closeAll('iframe');
	          });
	        }
	      }
	    });
	}
};
window.onmessage = function(e) {
	action[e.data.action](e.data.data);
}
</script>